﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SLBehaviourSystem
{
    [CompositeNode]
    public class SquenceNode : CompositeNode
    {
        protected override void OnInitData()
        {

        }

        protected override void CheckChild()
        {
            childNodes[curIndex].Excute();
        }

        protected override void OnReset()
        {
            curIndex = 0;
        }

        protected override bool CheckInterruptState(BehaviourNodeState state)
        {
            return  state == BehaviourNodeState.Failure || state == BehaviourNodeState.Running;
        }

        protected override void OnChildNodeComplete()
        {
            childNodeState = childNodes[curIndex].CurNodeState;
            if (childNodeState == BehaviourNodeState.Running)
            {
                curNodeState = BehaviourNodeState.Running;
            }
            else if (childNodeState == BehaviourNodeState.Failure)
            {
                curNodeState = BehaviourNodeState.Failure;
            }
            else
            {
                if (curIndex == childNodes.Count - 1)
                {
                    curNodeState = BehaviourNodeState.Success;
                }
                else
                {
                    curNodeState = BehaviourNodeState.Running;
                }
            }
            base.OnChildNodeComplete();
        }
    }
}
